package com.ht.dao;

import com.ht.bean.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface HouqingDao {

    //维修管理查询
    @Select("select ep.equipmentId,ep.equipmentType,ep.status,sc.className,st.stuname,ep.remark,dp.depName,ep.userType,ep.startTime,ep.endTime from equipmentrepair ep ,studentclass sc ,student st,dep dp where ep.classes=sc.classId and ep.student=st.stuId and ep.depId=dp.depid")
    List<Equipmentrepair>weixiulist();

    //id查询 模糊查询
    @Select({"<script>",
            "select * from equipmentrepair ep",
            "<where>",
            "<if test=\"ep.equipmentId!=null and ep.equipmentId!=''\">",
            " and ep.equipmentId=#{ep.equipmentId}",
            "</if>",
            "<if test=\"ep.equipmentType!=null and ep.equipmentType!=''\">",
            " and ep.equipmentType like concat('%',#{ep.equipmentType},'%')",
            "</if>",
            "</where>",
            " ORDER BY status+0 ASC  limit #{startIndex},#{pageSize}",
            "</script>"})
    List<Map> eplist(@Param("startIndex") Integer startIndex, @Param("pageSize")Integer pageSize, @Param("ep") Equipmentrepair equipmentrepair);

    //id查询 模糊查询的总页数
    @Select({"<script>",
            "select count(*) from equipmentrepair ep",
            "<where>",
            "<if test=\"ep.equipmentId!=null and ep.equipmentId!=''\">",
            " and ep.equipmentId=#{ep.equipmentId}",
            "</if>",
            "<if test=\"ep.equipmentType!=null and ep.equipmentType!=''\">",
            " and ep.equipmentType like concat('%',#{ep.equipmentType},'%')",
            "</if>",
            "</where>",
            "</script>"})
    public int countep(@Param("ep") Equipmentrepair equipmentrepair);

    //维修管理新增
    @Insert("insert into equipmentrepair values(null,#{equipmentType},#{status},#{classes},#{student},#{remark},#{depId},#{userType},now(),#{endTime})")
    public boolean weixiuadd(Equipmentrepair equipmentrepair);

    //维修管理删除
    @Delete("delete from equipmentrepair where equipmentId=#{equipmentId}")
    public boolean weixiudel(String equipmentId);


    //查询班级表
    @Select("select * from studentclass")
    List<Studentclass> classlist();

    //查询部门表
    @Select("select * from dep")
    List<Dep>deplist();


    //查询学生表
    @Select("select * from student")
    List<Student> listsd();

    //查询学生表
    @Select("select * from student where stuId=#{stuId}")
    List<Student> sdlist(Student student);

    //维修管理结束时间
    @Update("update equipmentrepair set status=#{status}  , endTime=now() where equipmentId=#{equipmentId}")
    public boolean weixiushijian(Equipmentrepair equipmentrepair);

    //维修管理根据id查找对象
    @Select("select * from equipmentrepair where equipmentId=#{equipmentId}")
    public Equipmentrepair weixiusel(String equipmentId);

    //维修管理修改
    @Update("update equipmentrepair set equipmentType=#{equipmentType},status=#{status},classes=#{classes},student=#{student},remark=#{remark},depId=#{depId},userType=#{userType},startTime=#{startTime},endTime=#{endTime} where equipmentId=#{equipmentId}")
    public boolean weixiuupd(Equipmentrepair equipmentrepair);



    //-------------------------------------------------------------------------------------------------------------------------------------------------
    //楼栋管理👇↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓------------------------------------------------------------------------------------------------------------------------
    //楼栋id查询 模糊查询
    @Select({"<script>",
            "select * from studentfloor ",
            "<where>",
            "<if test=\"sf.floorId!=null and sf.floorId!=''\">",
            " and floorId=#{sf.floorId}",
            "</if>",
            "<if test=\"sf.floorName!=null and sf.floorName!=''\">",
            " and floorName like concat('%',#{sf.floorName},'%')",
            "</if>",
            "</where>",
            " limit #{startIndex},#{pageSize}",
            "</script>"})
    List<Map> loudonglist(@Param("startIndex") Integer startIndex,@Param("pageSize")Integer pageSize,@Param("sf") Studentfloor studentfloor);


    //id查询 模糊查询的总页数
    @Select({"<script>",
            "select count(*) from studentfloor ",
            "<where>",
            "<if test=\"sf.floorId!=null and sf.floorId!=''\">",
            " and floorId=#{sf.floorId}",
            "</if>",
            "<if test=\"sf.floorName!=null and sf.floorName!=''\">",
            " and floorName like concat('%',#{sf.floorName},'%')",
            "</if>",
            "</where>",
            "</script>"})
    public int loudongcount(@Param("sf") Studentfloor studentfloor);


    //楼栋管理新增
    @Insert("insert into studentfloor values(null,#{floorName})")
    public boolean loudongadd(Studentfloor studentfloor);

    //楼栋管理删除
    @Delete("delete from studentfloor where floorId=#{floorId}")
    public boolean loudongdel(String floorId);

    //楼栋管理根据id查找对象
    @Select("select * from studentfloor where floorId=#{floorId}")
    public Studentfloor studentfloor(String floorId);

    //楼栋管理修改
    @Update("update studentfloor set floorName=#{floorName} where floorId=#{floorId}")
    public boolean loudongupd(Studentfloor studentfloor);



    //宿舍管理↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓++++++++++++++++++++++++++----------------------------+++++++++++++++++++++++++++------------------------+++++++++++++++++
    //------------------------------------------------------------------------------------------------------------------------------------------------------------

    //id查询 模糊查询
    @Select({"<script>",
            "select st.huorId,st.huorName,st.addr,st.count,sf.floorName,st.numberBeds,st.numberBeds,st.huoeIddsc from studenthuor st ,studentfloor sf  ",
            "<where>",
            " st.floorId=sf.floorId ",
            "<if test=\"st.huorId!=null and st.huorId!=''\">",
            " and huorId=#{st.huorId}",
            "</if>",
            "<if test=\"st.huoeIddsc!=null and st.huoeIddsc!=''\">",
            " and huoeIddsc like concat('%',#{st.huoeIddsc},'%')",
            "</if>",
            "</where>",
            " limit #{startIndex},#{pageSize}",
            "</script>"})
    List<Map> sushelist(@Param("startIndex") Integer startIndex,@Param("pageSize")Integer pageSize,@Param("st") Studenthuor studenthuor);


    //id查询 模糊查询的总页数
    @Select({"<script>",
            "select count(*) from studenthuor st ,studentfloor sf ",
            "<where>",
            " st.floorId = sf.floorId ",
            "<if test=\"st.huorId!=null and st.huorId!=''\">",
            " and huorId=#{st.huorId}",
            "</if>",
            "<if test=\"st.huoeIddsc!=null and st.huoeIddsc!=''\">",
            " and huoeIddsc like concat('%',#{st.huoeIddsc},'%')",
            "</if>",
            "</where>",
            "</script>"})
    public int sushecount(@Param("st") Studenthuor studenthuor);


    //宿舍管理新增
    @Insert("insert into studenthuor values(null,#{huorName},#{addr},#{count},#{floorId},#{numberBeds},#{huoeIddsc})")
    public boolean susheadd(Studenthuor studenthuor);

    //宿舍管理删除
    @Delete("delete from studenthuor where huorId=#{huorId}")
    public boolean sushedel(String huorId);

    //宿舍管理根据id查找对象
    @Select("select * from studenthuor where huorId=#{huorId}")
    public Studenthuor studenthuor(String huorId);

    //宿舍管理修改
    @Update("update studenthuor set huorName=#{huorName},addr=#{addr},count=#{count},floorId=#{floorId},numberBeds=#{numberBeds},huoeIddsc=#{huoeIddsc} where huorId=#{huorId}")
    public boolean susheupd(Studenthuor studenthuor);

    //楼栋查询
    @Select("select * from studentfloor")
    List<Studentfloor> sflist();

    //维修管理根据id查找对象
    @Select("select * from studenthuor where huorId=#{huorId}")
    public Studenthuor sushesel(String huorId);
}
